home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / write.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  21KB  |  759 lines

  1. #include "write.h"
  2. #include "ask_hot.h"
  3. #include "ask_str.h"
  4.  
  5. void settext()
  6.     {
  7.     settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  8.     settextjustify(LEFT_TEXT, TOP_TEXT);
  9.     setcolor(pColorSet->colors.ATTR_COLOR);
  10.     }
  11. ////////////////////////
  12. Write::Write(rect coordinates, char* swapName, char* fName, char* h,
  13.          int s, BORDERS b_type, BORDERS hdr_b_type, int pat, int hdr_pat)
  14.     : Window(coordinates, fName, h, s, b_type, hdr_b_type, FIXED, pat,
  15.              hdr_pat)
  16.     {
  17.     clip = NULL;
  18.     mark = 0;
  19.     mark_begin = mark_end = -1;
  20.     status = INS | SAVED;
  21.     swapFile = swapName == NULL ? NULL : strdup(swapName);
  22.     buffer = NULL;
  23.     line_num = 0;
  24.     curs = loc(0, 0);
  25.     xTab = 0;
  26.     total = 0;
  27.     }
  28. /////////////////////////////////   // ATTENTION !!!
  29. Write::~Write()                     // The Write is a very simple editor,
  30.     {                               // Which could be used as POPUP
  31.     delete swapFile;                // window object only. The ~Write
  32.     swapFile = NULL;
  33.     delete clip;
  34.     }                               // does not delete buffer - we suppose
  35. /////////////////////////////////   // that you first call hide() function.
  36. void Write::load_file()
  37.     {
  38.     FILE* file;
  39.     if((file = fopen(swapFile, "rb")) == NULL)
  40.         file = fopen(swapFile, "wb");
  41.  
  42.     delete buffer;
  43.     buffer = (char**)malloc(STRINGS * sizeof(char*));  // N lines only
  44.     for(int i = 0; i < STRINGS; i++)                   // Allocate 100 strings
  45.         buffer[i] = new char[STRING_LEN];
  46.     for(total = 0; total < STRINGS; total++)
  47.         {
  48.         if(fgets(buffer[total], STRING_LEN, file) == NULL)
  49.             break;
  50.         char* string;
  51.     if((string = strchr(buffer[total], '\n')) == NULL)
  52.         buffer[total][STRING_LEN - 1] = '\r';
  53.         else
  54.         {
  55.         buffer[total][string - buffer[total]] = '\0';
  56.             buffer[total][string - buffer[total] - 1] = '\r';
  57.             }
  58.         }
  59.     buffer[total][0] = '\r';
  60.     buffer[total][1] = '\0';
  61.  
  62.     fclose(file);
  63.     }
  64. ////////////////////////////////
  65. void Write::unload_file()
  66.     {
  67.     if(!(status & SAVED) && ask_save())
  68.     swap();
  69.     for(int i = 0; i < STRINGS; i++)
  70.     delete buffer[i];
  71.     delete buffer;
  72.     buffer = NULL;
  73.     }
  74. ////////////////////////////////
  75. void Write::show()
  76.     {
  77.     Window::show();
  78.     load_file();
  79.     line_num = 0;
  80.     curs = loc(0, 0);
  81.     xTab = 0;
  82.     show_text(loc(0, 0));
  83.     showCursor();
  84.     }
  85. ////////////////////////
  86. void Write::hide()
  87.     {
  88.     unload_file();
  89.     Window::hide();
  90.     }
  91. ////////////////////////
  92. void Write::show_text(loc from)
  93.     {
  94.     loc res = curs;
  95.  
  96.     settext();
  97.  
  98.     rect r = user_screen();
  99.     bar(rect(r.origin.X, r.origin.Y + curs.Y, r.corner.X, r.corner.Y),
  100.             (int)pColorSet->colors.BAK_COLOR,
  101.             (int)pColorSet->colors.ATTR_COLOR, (uchar*)::pattern[pattern]);
  102.     setviewport(r.origin.X, r.origin.Y, r.corner.X, r.corner.Y, 1);
  103.     while(curs.Y < user_screen().height() && from.Y <= total)
  104.     {
  105.         if(from.X <= strlen(buffer[from.Y]))
  106.             {
  107.             if(from.Y >= mark_begin && from.Y <= mark_end)
  108.                 {
  109.                 bar(rect(0, curs.Y,
  110.             r.width(), curs.Y + (int)pScreenSet->sub_interval),
  111.                     (int)pColorSet->colors.MARK_BAK_COLOR,
  112.                     (int)pColorSet->colors.MARK_COLOR,
  113.             (uchar*)::pattern[pattern]);
  114.                 setcolor((int)pColorSet->colors.MARK_COLOR);
  115.                 }
  116.             else
  117.                 setcolor((int)pColorSet->colors.ATTR_COLOR);
  118.         outtextxy(curs.X, curs.Y, buffer[from.Y] + from.X);
  119.             }
  120.     from.Y++;
  121.     curs.Y += pScreenSet->sub_interval;
  122.         curs.X = 0;
  123.     moveto(curs);
  124.     }
  125.  
  126.     setviewport(0, 0, getmaxx(), getmaxy(), 1);
  127.     curs = res;
  128.     }
  129. //////////////////////////////
  130. void Write::outtext(int x, int y, char* txt)
  131.     {
  132.     settext();
  133.  
  134.     rect r = user_screen();
  135.     setviewport(r.origin.X, r.origin.Y, r.corner.X, r.corner.Y, 1);
  136.  
  137.     int right =
  138.         curs.X + textwidth(txt) > r.width() - pScreenSet->standart_width
  139.         ? r.width() : curs.X + textwidth(txt)
  140.       + pScreenSet->standart_width;
  141.     rect r1(curs.X, curs.Y, right,
  142.         curs.Y + pScreenSet->sub_interval - 1);
  143.     if(line_num >= mark_begin && line_num <= mark_end)
  144.         {
  145.         setcolor((int)pColorSet->colors.MARK_COLOR);
  146.         bar(r1, (int)pColorSet->colors.MARK_BAK_COLOR,
  147.             (int)pColorSet->colors.MARK_COLOR, (uchar*)::pattern[pattern]);
  148.         }
  149.     else
  150.         {
  151.     setcolor((int)pColorSet->colors.ATTR_COLOR);
  152.         bar(r1, (int)pColorSet->colors.BAK_COLOR,
  153.             (int)pColorSet->colors.FILL_COLOR, (uchar*)::pattern[pattern]);
  154.         }
  155.     outtextxy(x, y, txt);
  156.     setviewport(0, 0, getmaxx(), getmaxy(), 1);
  157.     }
  158. //////////////////////////////
  159. void Write::swap()
  160.     {
  161.     FILE* file;
  162.     if((file = fopen(swapFile, "wb")) == NULL)
  163.         return;
  164.     for(int i = 0; i <= total; i++)
  165.         {
  166.     fputs(buffer[i], file);
  167.         fputc('\n', file);
  168.         }
  169.     fclose(file);
  170.     status = (status & INS) | SAVED;
  171.     }
  172. //////////////////////////////
  173. void Write::exe(int act)
  174.     {
  175.     e.what = act ? KEYEVENT : NOEVENT;
  176.  
  177.     switch(act)
  178.     {
  179.     case AC_LEFT:   e.key = EVENT_LEFT; break;
  180.     case AC_RIGHT:  e.key = EVENT_RIGHT; break;
  181.     case AC_UP:     e.key = EVENT_UP; break;
  182.     case AC_DOWN:   e.key = EVENT_DN; break;
  183.     case AC_PG_UP:  e.key = EVENT_PG_UP; break;
  184.     case AC_PG_DN:  e.key = EVENT_PG_DN; break;
  185.     case AC_CTRL_PG_UP: e.key = EVENT_CTRL_PG_UP; break;
  186.     case AC_CTRL_PG_DN: e.key = EVENT_CTRL_PG_DN; break;
  187.     case AC_CANCEL: e.key = EVENT_ESC; break;
  188.     case AC_OK:     e.key = EVENT_F2; break;
  189.     }
  190.     mouseHideCursor();
  191.     hilite();
  192.     int on = 0;
  193.  
  194.     mouseShowCursor();
  195.  
  196.     while(1)
  197.     {
  198.     mouseShowCursor();
  199.     if(!act && !(e.what == MOUSEEVENT && !on))
  200.         get_event();
  201.     else
  202.         on = 1;
  203.  
  204.     mouseHideCursor();
  205.     if(e.what == KEYEVENT)
  206.         switch(e.key)
  207.         {
  208.         case EVENT_F1: global_i[0] = action_type;
  209.             return;
  210.         case EVENT_RIGHT: right(1); break;
  211.         case EVENT_LEFT: left(1);   break;
  212.         case EVENT_UP: up(1); break;
  213.         case EVENT_DN: dn(1); break;
  214.         case EVENT_HOME: home(); break;
  215.         case EVENT_END:  end();  break;
  216.         case EVENT_PG_UP: pgUp(); break;
  217.         case EVENT_PG_DN: pgDn(); break;
  218.         case EVENT_CTRL_PG_UP: toTop(); break;
  219.         case EVENT_CTRL_PG_DN: toBottom(); break;
  220.  
  221.         case EVENT_ESC:
  222.                 case EVENT_F6:
  223.         case EVENT_F10:
  224. //        case EVENT_TAB:
  225.         case EVENT_ALT_TAB:
  226.         case EVENT_ALT_F4:
  227.             global_num = 1; global_i[0] = 0;
  228.                     return;
  229.         case EVENT_F2: swap(); unhilite(); global_num = 1;
  230.             global_i[0] = action_type; return;
  231.  
  232.         case EVENT_DEL: status = (status & INS);
  233.             del(); break;
  234.         case EVENT_INS:
  235.             status = (status & INS);
  236.             setInsert();
  237.             break;
  238.         case EVENT_BKSP: status = (status & INS);
  239.             bksp(); break;
  240.  
  241.         case EVENT_CTRL_Y:
  242.             ctrl_y(); status = (status & INS); break;
  243.         case EVENT_RETURN:
  244.             processKey('\n'); status = (status & INS); break;
  245.                 case EVENT_SHIFT_F6:  // Begin / end mark
  246.                     if(mark)
  247.                         mark_end = line_num;
  248.                     else
  249.                         mark_begin = line_num;
  250.                     mark = !mark;
  251.                     hideCursor();
  252.                     int res = curs.Y;
  253.                     curs.Y = 0;
  254.                     show_text(loc(xTab, 0));
  255.                     curs.Y = res;
  256.                     showCursor();
  257.                     break;
  258.                 case EVENT_SHIFT_F2:
  259.                     copy();
  260.                     break;
  261.                 case EVENT_SHIFT_F3:
  262.                     cut();
  263.                     break;
  264.                 case EVENT_SHIFT_F4:
  265.                     paste();
  266.                     break;
  267. /*                case EVENT_ALT_F7:             // Unremark if you want
  268.                     if(!ask_str(rectangle))      // to get more trouble.
  269.                 break;
  270.                     hideCursor();
  271.                     search();
  272.                     Border::show();
  273.                     showCursor();
  274.                     break;
  275.  
  276.                 case EVENT_F7:
  277.                     hideCursor();
  278.                     search();
  279.                     Border::show();
  280.                     showCursor();
  281.                     break;
  282.  
  283. */        default:
  284.             if(e.is_char())
  285.                 {
  286.             status = (status & INS);
  287.             processKey(e.key);
  288.                         }
  289.             break;
  290.         }
  291.     else
  292.         {
  293.         if(!mouse_in(e.where()))  // outside of edit window
  294.         {
  295.         unhilite();
  296.         global_num = 0; global_i[0] = AC_NULL;
  297.         return;
  298.         }
  299.         }
  300.         if(act)    // leave menu and return to the object which calls it
  301.         {      // after single processing of "act" command
  302.         return;
  303.         }
  304.  
  305.     }
  306.     }
  307. ///////////////////////////////
  308. void Write::search()
  309.     {
  310.     mark = 0;
  311.     for(int i = line_num; i < total; i++)
  312.         {
  313.         char* s;
  314.     if((s = strstr(buffer[i] + xTab + textX(curs.X), global[0])) != NULL)
  315.         {
  316.             xTab = s - buffer[i];
  317.  
  318.             rect r = user_screen();
  319.             curs = loc(0, 0);
  320.             line_num = i;
  321.             show_text(loc(xTab, line_num));
  322.             break;
  323.         }
  324.         }
  325.     }
  326. ///////////////////////////////
  327. void Write::showCursor()
  328.     {
  329.     rect r = user_screen();
  330.     setviewport(r.origin.X, r.origin.Y, r.corner.X, r.corner.Y, 1);
  331.     setwritemode(XOR_PUT);
  332.     setlinestyle(SOLID_LINE, 1, 3);
  333.     moveto(curs);
  334.     lineto(curs.X, curs.Y + pScreenSet->standart_height);
  335.     setwritemode(COPY_PUT);
  336.     setviewport(0, 0, getmaxx(), getmaxy(), 1);
  337.     }
  338. //////////////////////////////
  339. int Write::copy()
  340.     {
  341.     if(mark_begin == -1)
  342.         return 0;
  343.     delete clip;
  344.     clip = new KH_STRTABLE(0);
  345.  
  346.     for(int i = mark_begin; i <= mark_end; i++)
  347.         {
  348.     clip->add(buffer[i]);
  349.         }
  350.     return 1;
  351.     }
  352. ////////////////
  353. void Write::cut()
  354.     {
  355.     if(!copy())
  356.         return;
  357.     for(int i = mark_begin, j = mark_end; i < mark_end && i < total; i++, j++)
  358.         buffer[i] = buffer[j];
  359.     total -= mark_end - mark_begin;
  360.     }
  361. ////////////
  362. void Write::paste()
  363.     {
  364.     if(clip == NULL)
  365.         return;
  366.     hideCursor();
  367.     for(int i = total; i >= line_num; i--)
  368.         strcpy(buffer[i + clip->used], buffer[i]);
  369.  
  370.     for(int j = 0, k = line_num; j < clip->used; j++, k++)
  371.         strcpy(buffer[k], clip->strings[j]);
  372.  
  373.     total += clip->used;
  374.  
  375.     rect r = user_screen();
  376.     show_text(loc(xTab, line_num));
  377.     showCursor();
  378.     }
  379. ////////////
  380. void Write::up(int sh)
  381.     {
  382.     hideCursor();
  383.     rect r = user_screen();
  384.  
  385.     if(curs.Y >= sh * pScreenSet->sub_interval)
  386.         {
  387.     curs.Y -= sh * pScreenSet->sub_interval;
  388.         line_num -= sh;
  389.         }
  390.     else
  391.         {
  392.     if(line_num < sh)
  393.         {
  394.             showCursor();
  395.         return;
  396.             }
  397.         line_num -= sh;
  398.         curs = loc(0, 0);
  399.         if(line_num < r.height() / pScreenSet->sub_interval)
  400.             {
  401.         show_text(loc(xTab, 0));
  402.             curs.Y = line_num * pScreenSet->sub_interval;
  403.             }
  404.         else
  405.             {
  406.             show_text(loc(xTab,
  407.             line_num - (r.height() / pScreenSet->sub_interval) + 1));
  408.             curs.Y = (r.height() / pScreenSet->sub_interval - 1)
  409.             * (pScreenSet->sub_interval);
  410.             }
  411.         }
  412.  
  413.     showCursor();
  414.     }
  415. /////////////////////////////
  416. void Write::dn(int sh)
  417.     {
  418.     if(line_num + sh >= total)
  419.     return;
  420.  
  421.     hideCursor();
  422.     rect r = user_screen();
  423.     if(curs.Y < r.height() - (sh + 1) * pScreenSet->sub_interval)
  424.         {
  425.     curs.Y += sh * pScreenSet->sub_interval;
  426.         line_num += sh;
  427.         }
  428.     else
  429.         {
  430.         curs = loc(0, 0);
  431.         line_num += sh;
  432.         show_text(loc(xTab, line_num));
  433.     }
  434.  
  435.     showCursor();
  436.     }
  437. /////////////////////////////////
  438. void Write::left(int sh)
  439.     {
  440.     hideCursor();
  441.     if(curs.X >= sh * pScreenSet->standart_width)
  442.     curs.X -= sh * pScreenSet->standart_width;
  443.     else if(xTab >= sh - textX(curs.X))
  444.         {
  445.         xTab -= (sh - textX(curs.X));
  446.         rect r = user_screen();
  447.         int res = curs.Y;
  448.         curs.X = 0;
  449.         curs.Y = 0;
  450.         show_text(loc(xTab,
  451.         line_num / (r.height() / pScreenSet->sub_interval)
  452.         * (r.height() / pScreenSet->sub_interval)));
  453.         curs.Y = res;
  454.     }
  455.     showCursor();
  456.     }
  457. ////////////////////////////////
  458. void Write::right(int sh)
  459.     {
  460.     hideCursor();
  461.     rect r = user_screen();
  462.     int len = strlen(buffer[line_num]);
  463.     int pos = textX(curs.X) + xTab;
  464.     if(curs.X < r.width() - sh * pScreenSet->standart_width
  465.         && pos < len - sh)
  466.     curs.X += sh * pScreenSet->standart_width;
  467.     else if(pos < len - sh)
  468.         {
  469.         xTab += sh;
  470.         int res = curs.Y;
  471.         curs.Y = 0;
  472.         show_text(loc(xTab,
  473.         line_num / (r.height() / pScreenSet->sub_interval)
  474.         * (r.height() / pScreenSet->sub_interval)));
  475.         curs.Y = res;
  476.     }
  477.     showCursor();
  478.     }
  479. ////////////////////////////////
  480. void Write::home()
  481.     {
  482.     int sh = xTab + textX(curs.X);
  483.     left(sh);
  484.     }
  485. ////////////////////////////////
  486. void Write::end()
  487.     {
  488.     int sh = strlen(buffer[line_num]) - (xTab + textX(curs.X)) - 1;
  489.     right(sh);
  490.     }
  491. ///////////////////////////////
  492. void Write::pgUp()
  493.     {
  494.     int sh = user_screen().height() / pScreenSet->sub_interval;
  495.     up(sh);
  496.     }
  497. ///////////////////////////////
  498. void Write::pgDn()
  499.     {
  500.     int sh = user_screen().height() / pScreenSet->sub_interval;
  501.     dn(sh);
  502.     }
  503. ///////////////////////////////
  504. void Write::toTop()
  505.     {
  506.     int sh = line_num;
  507.     up(sh);
  508.     }
  509. //////////////////////////////
  510. void Write::toBottom()
  511.     {
  512.     int sh = total - line_num - 1;
  513.     dn(sh);
  514.     }
  515. //////////////////////////////
  516. void Write::ctrl_y()
  517.     {
  518.     mark = 0;
  519.     hideCursor();
  520.     char* tmp = buffer[line_num];
  521.     for(int i = line_num; i < total; i++)
  522.         buffer[i] = buffer[i + 1];
  523.     buffer[total] = tmp;
  524.     total--;
  525.     curs.X = 0;
  526.     if(xTab)
  527.         {
  528.         rect r = user_screen();
  529.         xTab = 0;
  530.         show_text(loc(0,
  531.         line_num / (r.height() / pScreenSet->sub_interval)
  532.         * (r.height() / pScreenSet->sub_interval)));
  533.         }
  534.     else
  535.         show_text(loc(0, line_num));
  536.  
  537.     if(line_num >= mark_begin && line_num <= mark_end)
  538.         mark_end--;
  539.  
  540.     showCursor();
  541.     }
  542. /////////////////////////////
  543. int Write::append(int line)
  544.     {
  545.     if(strlen(buffer[line]) + strlen(buffer[line + 1])
  546.         > STRING_LEN)
  547.         return 0;
  548.     strcpy(buffer[line] + strlen(buffer[line] + 1),
  549.            buffer[line + 1]);
  550.     char* tmp = buffer[line + 1];
  551.     for(int i = line + 1; i < total; i++)
  552.         buffer[i] = buffer[i + 1];
  553.     buffer[total] = tmp;
  554.     total--;
  555.  
  556.     return 1;
  557.     }
  558. /////////////////////////////
  559. void Write::del()
  560.     {
  561.     mark = 0;
  562.     if(xTab + textX(curs.X) >= strlen(buffer[line_num]))
  563.         end();
  564.     int pos = xTab + textX(curs.X);
  565.     hideCursor();
  566.     if(pos == strlen(buffer[line_num] + 1))
  567.         {
  568.     if(line_num < total)
  569.             {
  570.         if(!append(line_num))
  571.             {
  572.         showCursor();
  573.                 return;
  574.                 }
  575.             int res = curs.X;
  576.             curs.X = 0;
  577.             if(line_num >= mark_begin && line_num <= mark_end)
  578.                 mark_end--;
  579.  
  580.         show_text(loc(xTab, line_num));
  581.             curs.X = res;
  582.  
  583.             }
  584.         }
  585.     else
  586.         {
  587.     for(int i = pos; i < strlen(buffer[line_num]); i++)
  588.         buffer[line_num][i] = buffer[line_num][i + 1];
  589.         outtext(curs.X, curs.Y, buffer[line_num] + pos);
  590.         }
  591.     showCursor();
  592.     }
  593. /////////////////////////////
  594. void Write::bksp()
  595.     {
  596.     mark = 0;
  597.     hideCursor();
  598.     rect r = user_screen();
  599.     if(xTab == 0 && curs.X == 0)
  600.         {
  601.         int width = strlen(buffer[line_num - 1] + 1);
  602.     if(line_num > 0)
  603.         if(!append(line_num - 1))
  604.             {
  605.             showCursor();
  606.                 return;
  607.                 }
  608.         line_num--;
  609.         if(line_num >= mark_begin && line_num <= mark_end)
  610.             mark_end--;
  611.  
  612.         if(screenXL(width) > r.width())
  613.             xTab = width - textX(r.width());
  614.         else
  615.             curs.X = screenXL(width);
  616.         if(curs.Y > 0)
  617.             curs.Y -= pScreenSet->sub_interval;
  618.         int res = curs.X;
  619.         curs.X = 0;
  620.         show_text(loc(xTab, line_num));
  621.         curs.X = res;
  622.         showCursor();
  623.         return;
  624.         }
  625.  
  626.     if(xTab + textX(curs.X) >= strlen(buffer[line_num]))
  627.         {
  628.     showCursor();
  629.     end();
  630.     hideCursor();
  631.     }
  632.     if(xTab != 0 && curs.X == 0)
  633.         {
  634.         xTab--;
  635.     for(int i = xTab; i < strlen(buffer[line_num]); i++)
  636.         buffer[line_num][i] = buffer[line_num][i + 1];
  637.         show_text(loc(xTab, line_num));
  638.     }
  639.     else
  640.         {
  641.         curs.X -= pScreenSet->standart_width;
  642.         int pos = textX(curs.X) + xTab;
  643.     for(int i = pos; i < strlen(buffer[line_num]); i++)
  644.         buffer[line_num][i] = buffer[line_num][i + 1];
  645.  
  646.         outtext(curs.X, curs.Y, buffer[line_num] + pos);
  647.     }
  648.     showCursor();
  649.     }
  650. /////////////////////////////
  651. void Write::processKey(uchar ch)
  652.     {
  653.     mark = 0;
  654.     rect r = user_screen();
  655.     if(xTab + textX(curs.X) >= strlen(buffer[line_num]))
  656.         end();
  657.     hideCursor();
  658.     if(ch == '\n')
  659.         {
  660.         if(total >= STRINGS - 1)                              // 99 == 100 - 1
  661.             {
  662.         showCursor();
  663.         return;
  664.             }
  665.         char* tmp = buffer[total + 1];
  666.         for(int i = total + 1; i > line_num + 1; i--)
  667.             buffer[i] = buffer[i - 1];
  668.         buffer[line_num + 1] = tmp;
  669.         strcpy(buffer[line_num + 1], buffer[line_num] + xTab
  670.         + textX(curs.X));
  671.         int len1 = xTab + textX(curs.X) + 1;
  672.         buffer[line_num][len1 - 1] = '\r';
  673.         buffer[line_num][len1] = '\0';
  674.         curs.X = 0;
  675.         int res = curs.Y;
  676.         if(xTab || curs.Y + pScreenSet->sub_interval > r.height())
  677.             {
  678.         curs.Y = 0;
  679.             if(line_num >= mark_begin && line_num <= mark_end)
  680.                 mark_end++;
  681.             show_text(loc(0,
  682.             line_num / (r.height() / pScreenSet->sub_interval)
  683.             * (r.height() / pScreenSet->sub_interval)));
  684.             }
  685.         else
  686.             {
  687.             if(line_num >= mark_begin && line_num <= mark_end)
  688.                 mark_end++;
  689.             show_text(loc(0, line_num));
  690.             }
  691.         xTab = 0;
  692.  
  693.         line_num++;
  694.         total++;
  695.         curs.Y = res + pScreenSet->sub_interval > r.height()
  696.             ? res : res + pScreenSet->sub_interval;
  697.     }
  698.     else
  699.         {
  700.         if(strlen(buffer[line_num]) >= STRING_LEN - 1)
  701.             {
  702.             showCursor();
  703.             return;
  704.             }
  705.         for(int i = strlen(buffer[line_num]);
  706.         i >= xTab + textX(curs.X); i--)
  707.             buffer[line_num][i + 1] = buffer[line_num][i];
  708.         buffer[line_num][i + 1] = ch;
  709.  
  710.         if(curs.X + pScreenSet->standart_width < r.width())
  711.             {
  712.         outtext(curs.X, curs.Y, buffer[line_num] + xTab
  713.                 + textX(curs.X));
  714.             curs.X += pScreenSet->standart_width;
  715.             }
  716.         else
  717.             {
  718.         xTab += textX(r.width()) + 1;
  719.             int res = curs.Y;
  720.             curs = loc(0, 0);
  721.             show_text(loc(xTab,
  722.             line_num / (r.height() / pScreenSet->sub_interval)
  723.             * (r.height() / pScreenSet->sub_interval)));
  724.             curs.Y = res;
  725.             }
  726.     }
  727.     showCursor();
  728.     }
  729. /////////////////////////////
  730. void Write::repose(rect new_coord)
  731.     {
  732.     Window::repose(new_coord);
  733.     }
  734. ///////////////////////////
  735. /*
  736. void main()
  737.     {
  738.     if(!init_KNOW_HOW())
  739.         return;
  740.     setfillstyle(SOLID_FILL, pColorSet->colors.BAK_COLOR);
  741.     bar(0, 0, getmaxx(), getmaxy());
  742.  
  743.     Write s(rect(10, 0, 60, 24), "work.txt", "window.pcy", "EDITOR",
  744.            8, SHOW_BORDER, SHOW_BORDER, 0, 0);
  745.  
  746.     s.set_mark(2, 3);
  747.     s.show_window();
  748.     s.hide();
  749.     s.repose(rect(0, 0, 40, 20));
  750.     s.show_window();
  751.  
  752.     s.exe();
  753.  
  754.     s.hide();
  755.  
  756.     close_KNOW_HOW();
  757.     closegraph();
  758.     }
  759. */